import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from "redux"
import Top from '../../components/Top/Top'
import { actions, getCateList } from '../../store/modules/cate'
import {Link} from "react-router-dom"
import querystring from "querystring";
import "./Cate.css"
export class Cate extends Component {
    componentDidMount() {
        // console.log(this.props);
        let { cate: { reqGoods }, location: { search } } = this.props
        let id=querystring.parse(search.slice(1))
        // console.log(id);
        reqGoods(id.id) 
    }
    render() {
        let title = "cate"
        let { CateList } = this.props
        return (
            <div>
                <Top title={title}></Top>
                {
                    CateList.map((item) => (
                        <Link className="cate_box" to="/detail" key={item.id} >
                            <div>id:{item.id}</div>
                            <img src={item.img} alt="" />
                            <div>{item.goodsname}</div>
                            <div>price:{item.price}</div>
                            <div>market_price:{item.market_price}</div>
                        </Link>
                    ))
                }
            </div>
        )
    }
}

const mapStateToProps = (state) => ({
    CateList: getCateList(state)
})

const mapDispatchToProps = dispatch => ({
    cate: bindActionCreators(actions, dispatch)
})


export default connect(mapStateToProps, mapDispatchToProps)(Cate)
